<template>
  <div :loading="isloading">
    <div class="ant-table_container">
      <a-table
        bordered
        :data-source="tableData"
        :columns="tableColumns"
        :pagination="false"
        :scroll="{ x: 2000 }"
      >
        <div
          v-for="item in scopedSlots"
          v-bind:key="item"
          :slot="item"
          slot-scope="text, record"
        >
          <slot :name="item" :text="text" :row="record"></slot>
        </div>
      </a-table>
    </div>
    <div class="ant-table_footer">
      <a-pagination
        v-model="pagination.currnet"
        :default-current="1"
        :total="pagination.total"
        show-quick-jumper
        @change="handleTableChange"
        @showSizeChange="showSizeChange"
        :pageSize="pagination.pagesize"
        show-size-changer
      />
    </div>
  </div>
</template>
<script>
export default {
  props: ['apiajaxfun', 'tablecol', 'colSlots', 'queryparam'],
  data() {
    return {
      tableColumns: this.tablecol,
      scopedSlots: this.colSlots,
      querywhere: this.queryparam,
      pagination: {
        currnet: 1,
        pagesize: 8,
        total: 0
      },
      isloading: false,
      tableData: []
    }
  },

  methods: {
    loadData(pagenum) {
      const param = this.querywhere
      param.page = pagenum !== undefined ? pagenum : this.pagination.currentpage
      param.rows = this.pagination.pagesize
      this.isloading = true
      this.configshowcel = []
      this.allcels = []
      this.apiajaxfun(this.querywhere).then(res => {
        this.isloading = false
        if (res.code === 0 && res.success) {
          this.pagination.current = param.page
          this.pagination.total = res.totalcount
          this.tableData = res.data
        } else {
          this.$message.error(res.msg)
        }
      })
    },

    handleTableChange(pagination) {
      this.loadData(pagination)
    },
    showSizeChange(page, pageSize) {
      this.pagination.pagesize = pageSize
      this.loadData(1)
    }
  },
  computed: {},
  created() {
    this.loadData(1)
  }
}
</script>
